﻿// <copyright file="XmlItemDataReaderLoaderTest.cs" company="Oleg V. Polikarpotchkin">
// Copyright © 2008-2009 Oleg V. Polikarpotchkin. All Right Reserved
// </copyright>
// <author>Oleg V. Polikarpotchkin</author>
// <email>ov-p@yandex.ru</email>
// <date>2009-04-12</date>
// <summary>WPF OpenWPFChart library. Helpers.XmlItemDataReader.Loader class Test.</summary>
// <revision>$Id$</revision>

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenWPFChart.Helpers.XmlItemDataReader;

namespace Tests
{
    /// <summary>
	/// This is a test class for <see cref="OpenWPFChart.Helpers.XmlItemDataReader.Loader"/>
	/// class and is intended to contain all Loader Unit Tests
    ///</summary>
	[TestClass()]
	public class XmlItemDataReaderLoaderTest
	{
		#region TestContext
		private TestContext testContextInstance;

		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext
		{
			get
			{
				return testContextInstance;
			}
			set
			{
				testContextInstance = value;
			}
		}
		#endregion TestContext

		#region Additional test attributes
		// 
		//You can use the following additional attributes as you write your tests:
		//
		//Use ClassInitialize to run code before running the first test in the class
		//[ClassInitialize()]
		//public static void MyClassInitialize(TestContext testContext)
		//{
		//}
		//
		//Use ClassCleanup to run code after all tests in a class have run
		//[ClassCleanup()]
		//public static void MyClassCleanup()
		//{
		//}
		//
		//Use TestInitialize to run code before running each test
		//[TestInitialize()]
		//public void MyTestInitialize()
		//{
		//}
		//
		//Use TestCleanup to run code after each test has run
		//[TestCleanup()]
		//public void MyTestCleanup()
		//{
		//}
		//
		#endregion

		/// <summary>
		/// Test for successful multiple points series load.
		///</summary>
		[TestMethod()]
		public void MultipleSeriesTest()
		{
			string xmlSeries = @"<?xml version='1.0' encoding='utf-8'?>
			<Items xmlns='urn:ItemData-schema'>
				<Points.Int.Double YName='y=x^2' XName='x'>
					<Point x='0' y='0'/>
					<Point x='1' y='0.01'/>
					<Point x='2' y='0.04'/>
					<Point x='3' y='0.09'/>
					<Point x='4' y='0.16'/>
					<Point x='5' y='0.25'/>
					<Point x='6' y='0.36'/>
					<Point x='7' y='0.49'/>
					<Point x='8' y='0.64'/>
					<Point x='9' y='0.81'/>
					<Point x='1' y='1'/>
				</Points.Int.Double>
				<Points.Double YName='y=x^2' XName='x'>
					<Point x='0' y='0'/>
					<Point x='0.1' y='0.01'/>
					<Point x='0.2' y='0.04'/>
					<Point x='0.3' y='0.09'/>
					<Point x='0.4' y='0.16'/>
					<Point x='0.5' y='0.25'/>
					<Point x='0.6' y='0.36'/>
					<Point x='0.7' y='0.49'/>
					<Point x='0.8' y='0.64'/>
					<Point x='0.9' y='0.81'/>
					<Point x='1' y='1'/>
				</Points.Double>
				<Points.Double YName='Point Set'>
					<Point x='0.01' y='0.5'/>
					<Point x='0.15' y='0.25'/>
					<Point x='0.2' y='0.25'/>
					<Point x='0.35' y='0.97'/>
					<Point x='0.15' y='0.88'/>
					<Point x='0.44' y='0.44'/>
					<Point x='0.55' y='0.77'/>
					<Point x='0.66' y='0.05'/>
					<Point x='0.7' y='1.1'/>
					<Point x='0.85' y='0.2'/>
					<Point x='0.95' y='0.3'/>
				</Points.Double>
				<Points.Date.Double YName='temperature' XName='Date'>
					<Point x='2008-01-01' y='-20'/>
					<Point x='2008-02-01' y='-25'/>
					<Point x='2008-03-01' y='-15'/>
					<Point x='2008-04-01' y='-10'/>
					<Point x='2008-05-01' y='5'/>
					<Point x='2008-06-01' y='18'/>
					<Point x='2008-07-01' y='25'/>
					<Point x='2008-08-01' y='20'/>
					<Point x='2008-09-01' y='15'/>
					<Point x='2008-10-01' y='5'/>
					<Point x='2008-11-01' y='-5'/>
					<Point x='2008-12-01' y='-17'/>
				</Points.Date.Double>
				<Points.Month.Double YName='temperature' XName='Month'>
					<Point x='--01--' y='-20'/>
					<Point x='--02--' y='-25'/>
					<Point x='--03--' y='-15'/>
					<Point x='--04--' y='-10'/>
					<Point x='--05--' y='5'/>
					<Point x='--06--' y='18'/>
					<Point x='--07--' y='25'/>
					<Point x='--08--' y='20'/>
					<Point x='--09--' y='15'/>
					<Point x='--10--' y='5'/>
					<Point x='--11--' y='-5'/>
					<Point x='--12--' y='-17'/>
				</Points.Month.Double>
			</Items>";

			string xmlMappings = @"<?xml version='1.0' encoding='utf-8'?>
			<Mappings xmlns='urn:ItemData-mapping'>
				<Mapping>
					<XAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
					<YAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
					<YAxis xsd-type='double' clr-type='System.Double' type-string='Double'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
					<YAxis xsd-type='dateTime' clr-type='System.DateTime' type-string='DateTime'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
					<YAxis xsd-type='date' clr-type='System.DateTime' type-string='Date'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
					<YAxis xsd-type='gMonth' clr-type='System.Int32' type-string='Month'/>
				</Mapping>
				
				<Mapping>
					<XAxis xsd-type='double' clr-type='System.Double' type-string='Double'/>
					<YAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='double' clr-type='System.Double' type-string='Double'/>
					<YAxis xsd-type='double' clr-type='System.Double' type-string='Double'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='double' clr-type='System.Double' type-string='Double'/>
					<YAxis xsd-type='dateTime' clr-type='System.DateTime' type-string='DateTime'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='double' clr-type='System.Double' type-string='Double'/>
					<YAxis xsd-type='date' clr-type='System.DateTime' type-string='Date'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='double' clr-type='System.Double' type-string='Double'/>
					<YAxis xsd-type='gMonth' clr-type='System.Int32' type-string='Month'/>
				</Mapping>
				
				<Mapping>
					<XAxis xsd-type='dateTime' clr-type='System.DateTime' type-string='DateTime'/>
					<YAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='dateTime' clr-type='System.DateTime' type-string='DateTime'/>
					<YAxis xsd-type='double' clr-type='System.Double' type-string='Double'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='dateTime' clr-type='System.DateTime' type-string='DateTime'/>
					<YAxis xsd-type='dateTime' clr-type='System.DateTime' type-string='DateTime'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='dateTime' clr-type='System.DateTime' type-string='DateTime'/>
					<YAxis xsd-type='date' clr-type='System.DateTime' type-string='Date'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='dateTime' clr-type='System.DateTime' type-string='DateTime'/>
					<YAxis xsd-type='gMonth' clr-type='System.Int32' type-string='Month'/>
				</Mapping>
				
				<Mapping>
					<XAxis xsd-type='date' clr-type='System.DateTime' type-string='Date'/>
					<YAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='date' clr-type='System.DateTime' type-string='Date'/>
					<YAxis xsd-type='double' clr-type='System.Double' type-string='Double'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='date' clr-type='System.DateTime' type-string='Date'/>
					<YAxis xsd-type='dateTime' clr-type='System.DateTime' type-string='DateTime'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='date' clr-type='System.DateTime' type-string='Date'/>
					<YAxis xsd-type='date' clr-type='System.DateTime' type-string='Date'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='date' clr-type='System.DateTime' type-string='Date'/>
					<YAxis xsd-type='gMonth' clr-type='System.Int32' type-string='Month'/>
				</Mapping>
				
				<Mapping>
					<XAxis xsd-type='gMonth' clr-type='System.Int32' type-string='Month'/>
					<YAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='gMonth' clr-type='System.Int32' type-string='Month'/>
					<YAxis xsd-type='double' clr-type='System.Double' type-string='Double'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='gMonth' clr-type='System.Int32' type-string='Month'/>
					<YAxis xsd-type='dateTime' clr-type='System.DateTime' type-string='DateTime'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='gMonth' clr-type='System.Int32' type-string='Month'/>
					<YAxis xsd-type='date' clr-type='System.DateTime' type-string='Date'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='gMonth' clr-type='System.Int32' type-string='Month'/>
					<YAxis xsd-type='gMonth' clr-type='System.Int32' type-string='Month'/>
				</Mapping>
			</Mappings>";

			using (StringReader srMappings = new StringReader(xmlMappings))
			using (StringReader srSeries = new StringReader(xmlSeries))
			{
				IEnumerable<DataPointSeries> series = Loader.Load(srSeries, srMappings);
				Assert.AreEqual(5, series.Count());
			}
		}

		/// <summary>
		/// Required type mapping missed.
		///</summary>
		[TestMethod()]
		[ExpectedException(typeof(ValidationException))]
		public void MappingMissedTest()
		{
			string xmlSeries = @"<?xml version='1.0' encoding='utf-8'?>
			<Items xmlns='urn:ItemData-schema'>
				<Points.Date.Double YName='temperature' XName='Date'>
					<Point x='2008-01-01' y='-20'/>
					<Point x='2008-02-01' y='-25'/>
					<Point x='2008-03-01' y='-15'/>
					<Point x='2008-04-01' y='-10'/>
					<Point x='2008-05-01' y='5'/>
					<Point x='2008-06-01' y='18'/>
					<Point x='2008-07-01' y='25'/>
					<Point x='2008-08-01' y='20'/>
					<Point x='2008-09-01' y='15'/>
					<Point x='2008-10-01' y='5'/>
					<Point x='2008-11-01' y='-5'/>
					<Point x='2008-12-01' y='-17'/>
				</Points.Date.Double>
				<Points.Month.Double YName='temperature' XName='Month'>
					<Point x='--01--' y='-20'/>
					<Point x='--02--' y='-25'/>
					<Point x='--03--' y='-15'/>
					<Point x='--04--' y='-10'/>
					<Point x='--05--' y='5'/>
					<Point x='--06--' y='18'/>
					<Point x='--07--' y='25'/>
					<Point x='--08--' y='20'/>
					<Point x='--09--' y='15'/>
					<Point x='--10--' y='5'/>
					<Point x='--11--' y='-5'/>
					<Point x='--12--' y='-17'/>
				</Points.Month.Double>
			</Items>";

			string xmlMappings = @"<?xml version='1.0' encoding='utf-8'?>
			<Mappings xmlns='urn:ItemData-mapping'>
				<Mapping>
					<XAxis xsd-type='gMonth' clr-type='System.Int32' type-string='Month'/>
					<YAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='gMonth' clr-type='System.Int32' type-string='Month'/>
					<YAxis xsd-type='double' clr-type='System.Double' type-string='Double'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='gMonth' clr-type='System.Int32' type-string='Month'/>
					<YAxis xsd-type='dateTime' clr-type='System.DateTime' type-string='DateTime'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='gMonth' clr-type='System.Int32' type-string='Month'/>
					<YAxis xsd-type='date' clr-type='System.DateTime' type-string='Date'/>
				</Mapping>
				<Mapping>
					<XAxis xsd-type='gMonth' clr-type='System.Int32' type-string='Month'/>
					<YAxis xsd-type='gMonth' clr-type='System.Int32' type-string='Month'/>
				</Mapping>
			</Mappings>";

			using (StringReader srMappings = new StringReader(xmlMappings))
			using (StringReader srSeries = new StringReader(xmlSeries))
			{
				IEnumerable<DataPointSeries> series = Loader.Load(srSeries, srMappings);
				Assert.AreEqual(0, series.Count());
			}
		}

		/// <summary>
		/// Successful Int series load test.
		///</summary>
		[TestMethod()]
		public void IntSeriesTest()
		{
			string xmlSeries = @"<?xml version='1.0' encoding='utf-8'?>
			<Items xmlns='urn:ItemData-schema'>
				<Points.Int YName='y' XName='x'>
					<Point x='0' y='-0'/>
					<Point x='-2147483648' y='2147483645'/>
					<Point x='1' y='-1'/>
					<Point x='2' y='-3'/>
				</Points.Int>
			</Items>";
			string xmlMappings = @"<?xml version='1.0' encoding='utf-8'?>
			<Mappings xmlns='urn:ItemData-mapping'>
				<Mapping>
					<XAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
					<YAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
				</Mapping>
			</Mappings>";

			using (StringReader srMappings = new StringReader(xmlMappings))
			using (StringReader srSeries = new StringReader(xmlSeries))
			{
				IEnumerable<DataPointSeries> series = Loader.Load(srSeries, srMappings);
				Assert.AreEqual(1, series.Count());
			}
		}

		/// <summary>
		/// Successful Int.Double series load test.
		///</summary>
		[TestMethod()]
		public void IntDoubleSeriesTest()
		{
			string xmlSeries = @"<?xml version='1.0' encoding='utf-8'?>
			<Items xmlns='urn:ItemData-schema'>
				<Points.Int.Double YName='y' XName='x'>
					<Point x='0' y='-0'/>
					<Point x='-2147483648' y='1.401E-90'/>
					<Point x='1' y='NaN'/>
					<Point x='2' y='-INF'/>
					<Point x='33' y='INF'/>
				</Points.Int.Double>
			</Items>";
			string xmlMappings = @"<?xml version='1.0' encoding='utf-8'?>
			<Mappings xmlns='urn:ItemData-mapping'>
				<Mapping>
					<XAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
					<YAxis xsd-type='double' clr-type='System.Double' type-string='Double'/>
				</Mapping>
			</Mappings>";

			using (StringReader srMappings = new StringReader(xmlMappings))
			using (StringReader srSeries = new StringReader(xmlSeries))
			{
				IEnumerable<DataPointSeries> series = Loader.Load(srSeries, srMappings);
				Assert.AreEqual(1, series.Count());
			}
		}

		/// <summary>
		/// Successful Int.DateTime series load test.
		///</summary>
		[TestMethod()]
		public void IntDateTimeSeriesTest()
		{
			string xmlSeries = @"<?xml version='1.0' encoding='utf-8'?>
			<Items xmlns='urn:ItemData-schema'>
				<Points.Int.DateTime YName='y' XName='x'>
					<Point x='0' y='1999-05-31T13:20:00.000-05:00'/>
					<Point x='-2147483648' y='1999-05-31T18:20:00.000Z'/>
					<Point x='1' y='1999-05-31T13:20:00.000'/>
					<Point x='2' y='1999-05-31T13:20:00.000-05:32'/>
				</Points.Int.DateTime>
			</Items>";
			string xmlMappings = @"<?xml version='1.0' encoding='utf-8'?>
			<Mappings xmlns='urn:ItemData-mapping'>
				<Mapping>
					<XAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
					<YAxis xsd-type='dateTime' clr-type='System.DateTime' type-string='DateTime'/>
				</Mapping>
			</Mappings>";

			using (StringReader srMappings = new StringReader(xmlMappings))
			using (StringReader srSeries = new StringReader(xmlSeries))
			{
				IEnumerable<DataPointSeries> series = Loader.Load(srSeries, srMappings);
				Assert.AreEqual(1, series.Count());
			}
		}

		/// <summary>
		/// Successful Int.Date series load test.
		///</summary>
		[TestMethod()]
		public void IntDateSeriesTest()
		{
			string xmlSeries = @"<?xml version='1.0' encoding='utf-8'?>
			<Items xmlns='urn:ItemData-schema'>
				<Points.Int.Date YName='y' XName='x'>
					<Point x='0' y='2008-01-01'/>
					<Point x='-2147483648' y='0001-01-01'/>
					<Point x='1' y='2008-03-01'/>
					<Point x='2' y='0044-03-15'/>
				</Points.Int.Date>
			</Items>";
			string xmlMappings = @"<?xml version='1.0' encoding='utf-8'?>
			<Mappings xmlns='urn:ItemData-mapping'>
				<Mapping>
					<XAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
					<YAxis xsd-type='date' clr-type='System.DateTime' type-string='Date'/>
				</Mapping>
			</Mappings>";

			using (StringReader srMappings = new StringReader(xmlMappings))
			using (StringReader srSeries = new StringReader(xmlSeries))
			{
				IEnumerable<DataPointSeries> series = Loader.Load(srSeries, srMappings);
				Assert.AreEqual(1, series.Count());
			}
		}

		/// <summary>
		/// Successful Int.Time series load test.
		///</summary>
		///<remarks>
		/// <see cref="http://www.w3.org/TR/xmlschema11-2/#time"/>
		/// time represents instants of time that recur at the same point in each calendar day, 
		/// or that occur in some arbitrary calendar day.
		///</remarks>
		[TestMethod()]
		public void IntTimeSeriesTest()
		{
			string xmlSeries = @"<?xml version='1.0' encoding='utf-8'?>
			<Items xmlns='urn:ItemData-schema'>
				<Points.Int.Time YName='y' XName='x'>
					<Point x='0' y='14:30:00.000'/>
					<Point x='-2147483648' y='09:30:00.000-05:00'/>
					<Point x='1' y='14:30:00.000Z'/>
				</Points.Int.Time>
			</Items>";
			string xmlMappings = @"<?xml version='1.0' encoding='utf-8'?>
			<Mappings xmlns='urn:ItemData-mapping'>
				<Mapping>
					<XAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
					<YAxis xsd-type='time' clr-type='System.DateTime' type-string='Time'/>
				</Mapping>
			</Mappings>";

			using (StringReader srMappings = new StringReader(xmlMappings))
			using (StringReader srSeries = new StringReader(xmlSeries))
			{
				IEnumerable<DataPointSeries> seriesColl = Loader.Load(srSeries, srMappings);
				Assert.AreEqual(1, seriesColl.Count());
				DataPointSeries series = seriesColl.First();
				Assert.AreEqual(3, series.XsdPoints.Count());
				int i = 0;
				foreach (object[] pt in series.GetPoints())
				{
					DateTime now = DateTime.Now;
					now = new DateTime(now.Year, now.Month, now.Day);
					switch (i)
					{
						case 0:
							Assert.AreEqual(0, pt[0]);
							Assert.AreEqual(now + new TimeSpan(14, 30, 0), pt[1]);
							break;
						case 1:
							Assert.AreEqual(-2147483648, pt[0]);
							Assert.AreEqual(now + new TimeSpan(18, 30, 0), pt[1]);
							break;
						case 2:
							Assert.AreEqual(1, pt[0]);
							Assert.AreEqual(now + new TimeSpan(18, 30, 0), pt[1]);
							break;
					}
					i++;
				}
			}
		}

		/// <summary>
		/// Successful Int.Month series load test.
		///</summary>
		///<remarks>
		/// <see cref="http://www.w3.org/TR/xmlschema11-2/#gMonth"/>
		/// gMonth represents whole (Gregorian) months within an arbitrary year—months that recur at 
		/// the same point in each year.
		///</remarks>
		[TestMethod()]
		public void IntMonthSeriesTest()
		{
			string xmlSeries = @"<?xml version='1.0' encoding='utf-8'?>
			<Items xmlns='urn:ItemData-schema'>
				<Points.Int.Month YName='y' XName='x'>
					<Point x='0' y='--01--'/>
					<Point x='-2147483648' y='--02--'/>
					<Point x='1' y='--11--'/>
				</Points.Int.Month>
			</Items>";
			string xmlMappings = @"<?xml version='1.0' encoding='utf-8'?>
			<Mappings xmlns='urn:ItemData-mapping'>
				<Mapping>
					<XAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
					<YAxis xsd-type='gMonth' clr-type='System.DateTime' type-string='Month'/>
				</Mapping>
			</Mappings>";

			using (StringReader srMappings = new StringReader(xmlMappings))
			using (StringReader srSeries = new StringReader(xmlSeries))
			{
				IEnumerable<DataPointSeries> series = Loader.Load(srSeries, srMappings);
				Assert.AreEqual(1, series.Count());
			}
		}

		/// <summary>
		/// Successful Int.Day series load test.
		///</summary>
		///<remarks>
		/// <see cref="http://www.w3.org/TR/xmlschema11-2/#gDay"/>
		/// [Definition:]  gDay represents whole days within an arbitrary month—days that recur 
		/// at the same point in each (Gregorian) month.
		///</remarks>
		[TestMethod()]
		public void IntDaySeriesTest()
		{
			string xmlSeries = @"<?xml version='1.0' encoding='utf-8'?>
			<Items xmlns='urn:ItemData-schema'>
				<Points.Int.Day YName='y' XName='x'>
					<Point x='0' y='---01'/>
					<Point x='-2147483648' y='---02'/>
					<Point x='1' y='---31'/>
				</Points.Int.Day>
			</Items>";
			string xmlMappings = @"<?xml version='1.0' encoding='utf-8'?>
			<Mappings xmlns='urn:ItemData-mapping'>
				<Mapping>
					<XAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
					<YAxis xsd-type='gDay' clr-type='System.Int32' type-string='Day'/>
				</Mapping>
			</Mappings>";

			using (StringReader srMappings = new StringReader(xmlMappings))
			using (StringReader srSeries = new StringReader(xmlSeries))
			{
				IEnumerable<DataPointSeries> series = Loader.Load(srSeries, srMappings);
				Assert.AreEqual(1, series.Count());
			}
		}

		/// <summary>
		/// Successful Int.Year series load test.
		///</summary>
		///<remarks>
		/// <see cref="http://www.w3.org/TR/xmlschema11-2/#gYear"/>
		/// gYear represents Gregorian calendar years.
		///</remarks>
		[TestMethod()]
		public void IntYearSeriesTest()
		{
			string xmlSeries = @"<?xml version='1.0' encoding='utf-8'?>
			<Items xmlns='urn:ItemData-schema'>
				<Points.Int.Year YName='y' XName='x'>
					<Point x='0' y='0001'/>
					<Point x='-2147483648' y='1998'/>
					<Point x='1' y='3333'/>
				</Points.Int.Year>
			</Items>";
			string xmlMappings = @"<?xml version='1.0' encoding='utf-8'?>
			<Mappings xmlns='urn:ItemData-mapping'>
				<Mapping>
					<XAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
					<YAxis xsd-type='gYear' clr-type='System.Int32' type-string='Year'/>
				</Mapping>
			</Mappings>";

			using (StringReader srMappings = new StringReader(xmlMappings))
			using (StringReader srSeries = new StringReader(xmlSeries))
			{
				IEnumerable<DataPointSeries> series = Loader.Load(srSeries, srMappings);
				Assert.AreEqual(1, series.Count());
			}
		}

		/// <summary>
		/// Successful Int.YearMonth series load test.
		///</summary>
		///<remarks>
		/// <see cref="http://www.w3.org/TR/xmlschema11-2/#gYearMonth"/>
		/// gYearMonth represents specific whole Gregorian months in specific Gregorian years.
		///</remarks>
		[TestMethod()]
		public void IntYearMonthSeriesTest()
		{
			string xmlSeries = @"<?xml version='1.0' encoding='utf-8'?>
			<Items xmlns='urn:ItemData-schema'>
				<Points.Int.YearMonth YName='y' XName='x'>
					<Point x='0' y='0001-12'/>
					<Point x='-2147483648' y='1998-01'/>
					<Point x='1' y='3333-10'/>
				</Points.Int.YearMonth>
			</Items>";
			string xmlMappings = @"<?xml version='1.0' encoding='utf-8'?>
			<Mappings xmlns='urn:ItemData-mapping'>
				<Mapping>
					<XAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
					<YAxis xsd-type='gYearMonth' clr-type='System.Int32' type-string='YearMonth'/>
				</Mapping>
			</Mappings>";

			using (StringReader srMappings = new StringReader(xmlMappings))
			using (StringReader srSeries = new StringReader(xmlSeries))
			{
				IEnumerable<DataPointSeries> seriesColl = Loader.Load(srSeries, srMappings);
				Assert.AreEqual(1, seriesColl.Count());
				DataPointSeries series = seriesColl.First();
				Assert.AreEqual(3, series.XsdPoints.Count());
				int i = 0;
				foreach (object[] pt in series.GetPoints())
				{
					switch (i)
					{
						case 0:
							Assert.AreEqual(0, pt[0]);
							Assert.AreEqual(24, pt[1]);
							break;
						case 1:
							Assert.AreEqual(-2147483648, pt[0]);
							Assert.AreEqual(1998 * 12 + 1, pt[1]);
							break;
						case 2:
							Assert.AreEqual(1, pt[0]);
							Assert.AreEqual(3333 * 12 + 10, pt[1]);
							break;
					}
					i++;
				}
			}
		}

		/// <summary>
		/// Successful Int.MonthDay series load test.
		///</summary>
		///<remarks>
		/// <see cref="http://www.w3.org/TR/xmlschema11-2/#gYearMonth"/>
		/// gMonthDay represents whole calendar days that recur at the same point in each calendar 
		/// year, or that occur in some arbitrary calendar year.  (Obviously, days beyond 28 cannot 
		/// occur in all Februaries; 29 is nonetheless permitted.).
		/// <para>The ·day· value must be no more than 30 if ·month· is one of 4, 6, 9, or 11, and 
		/// no more than 29 if ·month· is 2.</para>
		///</remarks>
		[TestMethod()]
		public void IntMonthDaySeriesTest()
		{
			string xmlSeries = @"<?xml version='1.0' encoding='utf-8'?>
			<Items xmlns='urn:ItemData-schema'>
				<Points.Int.MonthDay YName='y' XName='x'>
					<Point x='0' y='--01-12'/>
					<Point x='-2147483648' y='--02-28'/>
					<Point x='1' y='--03-03'/>
				</Points.Int.MonthDay>
			</Items>";
			string xmlMappings = @"<?xml version='1.0' encoding='utf-8'?>
			<Mappings xmlns='urn:ItemData-mapping'>
				<Mapping>
					<XAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
					<YAxis xsd-type='gMonthDay' clr-type='System.DateTime' type-string='MonthDay'/>
				</Mapping>
			</Mappings>";

			using (StringReader srMappings = new StringReader(xmlMappings))
			using (StringReader srSeries = new StringReader(xmlSeries))
			{
				IEnumerable<DataPointSeries> seriesColl = Loader.Load(srSeries, srMappings);
				Assert.AreEqual(1, seriesColl.Count());
				DataPointSeries series = seriesColl.First();
				Assert.AreEqual(3, series.XsdPoints.Count());
				int i = 0;
				foreach (object[] pt in series.GetPoints())
				{
					int currentYear = DateTime.Now.Year;
					switch (i)
					{
						case 0:
							Assert.AreEqual(0, pt[0]);
							Assert.AreEqual(new DateTime(currentYear, 1, 12), pt[1]);
							break;
						case 1:
							Assert.AreEqual(-2147483648, pt[0]);
							Assert.AreEqual(new DateTime(currentYear, 2, 28), pt[1]);
							break;
						case 2:
							Assert.AreEqual(1, pt[0]);
							Assert.AreEqual(new DateTime(currentYear, 3, 3), pt[1]);
							break;
					}
					i++;
				}
			}
		}

		/// <summary>
		/// Successful Int.Duration series load test.
		///</summary>
		///<remarks>
		/// <see cref="http://www.w3.org/TR/xmlschema11-2/#duration"/>
		/// [Definition:]  duration is a datatype that represents durations of time.
		/// <para>The lexical representations of duration are more or less based on the pattern: 
		/// PnYnMnDTnHnMnS</para>
		///</remarks>
		[TestMethod()]
		public void IntDurationSeriesTest()
		{
			string xmlSeries = @"<?xml version='1.0' encoding='utf-8'?>
			<Items xmlns='urn:ItemData-schema'>
				<Points.Int.Duration YName='y' XName='x'>
					<Point x='-2147483648' y='P2000Y10M31DT09H32M7.4312S'/>
					<Point x='-0' y='P1M'/>
					<Point x='1' y='P30D'/>
				</Points.Int.Duration>
			</Items>";
			string xmlMappings = @"<?xml version='1.0' encoding='utf-8'?>
			<Mappings xmlns='urn:ItemData-mapping'>
				<Mapping>
					<XAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
					<YAxis xsd-type='duration' clr-type='System.TimeSpan' type-string='Duration'/>
				</Mapping>
			</Mappings>";

			using (StringReader srMappings = new StringReader(xmlMappings))
			using (StringReader srSeries = new StringReader(xmlSeries))
			{
				IEnumerable<DataPointSeries> series = Loader.Load(srSeries, srMappings);
				Assert.AreEqual(1, series.Count());
			}
		}

		/// <summary>
		/// Successful Int.String series load test.
		///</summary>
		///<remarks>
		/// <see cref="http://www.w3.org/TR/xmlschema11-2/#string"/>
		///</remarks>
		[TestMethod()]
		public void IntStringSeriesTest()
		{
			string xmlSeries = @"<?xml version='1.0' encoding='utf-8'?>
			<Items xmlns='urn:ItemData-schema'>
				<Points.Int.String YName='y' XName='x'>
					<Point x='-0' y='one'/>
					<Point x='-2147483648' y='two'/>
					<Point x='1' y='three'/>
				</Points.Int.String>
			</Items>";
			string xmlMappings = @"<?xml version='1.0' encoding='utf-8'?>
			<Mappings xmlns='urn:ItemData-mapping'>
				<Mapping>
					<XAxis xsd-type='int' clr-type='System.Int32' type-string='Int'/>
					<YAxis xsd-type='string' clr-type='System.Object' type-string='String'/>
				</Mapping>
			</Mappings>";

			using (StringReader srMappings = new StringReader(xmlMappings))
			using (StringReader srSeries = new StringReader(xmlSeries))
			{
				IEnumerable<DataPointSeries> seriesColl = Loader.Load(srSeries, srMappings);
				Assert.AreEqual(1, seriesColl.Count());
				DataPointSeries series = seriesColl.First();
				Assert.AreEqual(3, series.XsdPoints.Count());
				int i = 0;
				foreach (object[] pt in series.GetPoints())
				{
					int currentYear = DateTime.Now.Year;
					switch (i)
					{
						case 0:
							Assert.AreEqual(0, pt[0]);
							Assert.AreEqual("one", pt[1]);
							break;
						case 1:
							Assert.AreEqual(-2147483648, pt[0]);
							Assert.AreEqual("two", pt[1]);
							break;
						case 2:
							Assert.AreEqual(1, pt[0]);
							Assert.AreEqual("three", pt[1]);
							break;
					}
					i++;
				}
			}
		}

		/// <summary>
		/// A test for getTypeStrings
		///</summary>
		[TestMethod()]
		[DeploymentItem("OpenWPFChart.Helpers.dll")]
		public void getTypeStringsTest()
		{
			string tagName = "{urn:ItemData-schema}Points.Int.Double";
			string[] types = Loader_Accessor.getTypeStrings(tagName);
			Assert.AreEqual("Int", types[0]);
			Assert.AreEqual("Double", types[1]);
		}
	}
}
